import time

from selenium.webdriver.common.by import By

from base.app_base_page import AppBasePage



class PageSearch(AppBasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.a = By.ID, 'com.tpshop.malls:id/home_img'
        self.b = By.ID, 'com.tpshop.malls:id/default_search_et'
        self.c = By.ID, 'com.tpshop.malls:id/search_et'
        self.d = By.ID, 'com.tpshop.malls:id/search_btn'
        self.dr = By.ID, 'com.tpshop.malls:id/product_name_tv'
        # driver.tap([(28,366),(517,855)])
        # # 点击加入购物车
        # self.e=By.XPATH,'//android.widget.TextView[@resource-id="com.tpshop.malls:id/add_cart_tv"]'
        # # 点击确定
        # self.f=By.XPATH
        # # 点击购物车
        # self.g=By.XPATH,'//android.widget.ImageView[@resource-id="com.tpshop.malls:id/bottom_cart_img"]'
        # # 点击立即购买
        # self.h=By.XPATH,'//android.widget.TextView[@resource-id="com.tpshop.malls:id/buy_tv"]'
        # # 点击提交订单
        # self.i=By.XPATH,'//android.widget.TextView[@resource-id="com.tpshop.malls:id/submit_tv"]'
        # # 点击支付
        # self.j=By.XPATH,'//android.widget.Button[@resource-id="com.tpshop.malls:id/pay_btn"]'
        # # 输入支付密码
        # self.k=By.ID,'com.tpshop.malls:id/pwd_et'
        # # 点击确定
        # self.l=By.XPATH,'//android.widget.TextView[@resource-id="com.tpshop.malls:id/sure_tv"]'
        # # 获取订单确认成功
        #

    def app_pagesearch(self, username):
        time.sleep(2)
        self.app_base_click(self.a)
        time.sleep(2)
        self.app_base_click(self.b, )
        time.sleep(2)
        self.app_base_input(self.c, username)
        self.app_base_click(self.d)
        # self.app_base_click(self.e)
        # self.app_base_click(self.f)
        # self.app_base_click(self.g)
        # self.app_base_click(self.h)
        # self.app_base_click(self.i)
        # self.app_base_click(self.j)
        # self.app_base_input(self.k,password)
        # self.app_base_click(self.l)

    def gat_search_result(self):
        return self.app_fd_element(self.dr).text
    # 获取订单确认成功 A = By.XPATH, '//*[@text="确认订单成功"]').text
    #  print(A)
    #  # 暂停3秒]
    #  time.sleep(3)
    #  # 关闭驱动
    #  driver.quit()
